using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using Timer = System.Windows.Forms.Timer;

namespace NetworkConfigApp
{
    public partial class SplashForm : Form
    {
        private float progress = 0f;
        private Timer progressTimer;
        private Label statusLabel;
        private Label titleLabel;

        public SplashForm()
        {
            InitializeSplashForm();
        }

        private void InitializeSplashForm()
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Size = new Size(400, 200);
            this.BackColor = Color.FromArgb(30, 30, 30);
            this.Paint += SplashForm_Paint;

            // 创建标题标签
            titleLabel = new Label
            {
                Text = "网络配置工具",
                Font = new Font("微软雅黑", 16, FontStyle.Bold),
                ForeColor = Color.FromArgb(0, 192, 192),
                AutoSize = true,
                Location = new Point(20, 20)
            };
            this.Controls.Add(titleLabel);

            // 创建状态标签
            statusLabel = new Label
            {
                Text = "正在初始化...",
                Font = new Font("微软雅黑", 9),
                ForeColor = Color.FromArgb(0, 192, 192),
                AutoSize = true,
                Location = new Point(20, 120)
            };
            this.Controls.Add(statusLabel);

            // 创建进度条定时器
            progressTimer = new Timer();
            progressTimer.Interval = 50;
            progressTimer.Tick += ProgressTimer_Tick;
            progressTimer.Start();
        }

        private void ProgressTimer_Tick(object sender, EventArgs e)
        {
            progress += 0.02f;
            if (progress >= 1f)
            {
                progress = 1f;
                progressTimer.Stop();
            }
            this.Invalidate();
        }

        private void SplashForm_Paint(object sender, PaintEventArgs e)
        {
            // 绘制圆角矩形
            using (GraphicsPath path = new GraphicsPath())
            {
                int radius = 10;
                Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                path.AddArc(rect.X, rect.Y, radius * 2, radius * 2, 180, 90);
                path.AddArc(rect.Right - radius * 2, rect.Y, radius * 2, radius * 2, 270, 90);
                path.AddArc(rect.Right - radius * 2, rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90);
                path.AddArc(rect.X, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
                path.CloseAllFigures();

                // 设置窗体区域
                this.Region = new Region(path);

                // 绘制渐变背景
                using (LinearGradientBrush brush = new LinearGradientBrush(
                    rect,
                    Color.FromArgb(30, 30, 30),
                    Color.FromArgb(45, 45, 48),
                    LinearGradientMode.Vertical))
                {
                    e.Graphics.FillPath(brush, path);
                }

                // 绘制进度条
                Rectangle progressRect = new Rectangle(20, 150, this.Width - 40, 20);
                using (Pen pen = new Pen(Color.FromArgb(0, 192, 192), 2))
                {
                    e.Graphics.DrawRectangle(pen, progressRect);
                }

                // 填充进度条
                Rectangle fillRect = new Rectangle(
                    progressRect.X + 2,
                    progressRect.Y + 2,
                    (int)((progressRect.Width - 4) * progress),
                    progressRect.Height - 4);

                using (SolidBrush brush = new SolidBrush(Color.FromArgb(0, 192, 192)))
                {
                    e.Graphics.FillRectangle(brush, fillRect);
                }
            }
        }

        public void UpdateStatus(string status)
        {
            if (statusLabel != null && !statusLabel.IsDisposed)
            {
                statusLabel.Text = status;
            }
        }
    }
} 